home *** CD-ROM | disk | FTP | other *** search
- #/* CVS $Id: fortune.tcl,v 1.1 1995/02/03 16:24:49 zibi Exp $ */
- #!/bin/vtcl
- # graphical front end to NET2 Bsd fortune cmd
- # Not support percentage distributions or pattern match specifications
- # or a lot of switches...
- #
-
- # NET2 fortune switches :
- # -a all -l long, -s short, -e - treat files as equal size
- # -i nocase in pattern, -m <pattern> match pattern
- # -f print file list
- # -f file - use file for fortunes
- # -o offensive
- # -w wait before exiting
- #
-
- # Demoing VTcl for '94 devForum
- # Hops 08.18.94
-
-
- # ---------------- setup Globals ----------------
-
- set in_FortFile "fortunes" ;# Initial Fortune File ( all )
- set FortFile $in_FortFile
- set arg "" ;# switches passed to fortune binary
- set repeatStatus "" ;# Timer ID
-
- set Fort_bin "/usr/local/bin/fortune"
- set Fortunes_File_List { fortunes
- fortunes/fortunes fortunes/startrek
- fortunes/zippy fortunes/other-fortunes
- fortunes/fortunes-o
- }
-
-
-
- # ---------------- Callback Procs ----------------
-
- proc quitCB {cbs} {
- VtClose
- exit 0
- }
-
-
- # ---- Run the fortune and display the fortune string ----
-
- proc fortuneCB { outw cbs } {
- global arg FortFile Fort_bin
-
- catch { eval exec $Fort_bin -e -s $arg $FortFile } a
-
- #puts $a
- puts "./fortune $arg $FortFile "
-
- set arg ""
-
-
- WsSetValues $outw -value $a
- }
-
-
-
- # ---- Callback that sets the fortune file for the ComboBox ----
- proc CBFileItemCB { cbs} {
- global FortFile
-
- set FortFile [ keylget cbs value ]
-
- #puts $FortFile
-
- }
-
-
- # Reset fortune file
- proc FileMenuResetCB { cbs } {
- global FortFile in_FortFile cb
-
- set FortFile $in_FortFile
-
- WsSetValues $cb -value $FortFile
- }
-
-
- #proc destroyDialog {cbs } {
- #echo "destroy"
- # WsDestroyDialog [ keylget cbs widget ]
- #}
-
- proc nyiCB { cbs } {
- global app
-
- VtShowDialog [ VtErrorDialog $app.err \
- -message "This option is Not Yet Implemented" \
- -ok \
- -okLabel "Dismiss" \
- ]
- # -okCallback destroyDialog \
- # -autoDestroy False \
- # -autoHide False \
-
- }
-
-
- # ---- Repeat timer handling ----
-
- # display fortune and restore timer for next iteration
- proc TOfortuneCB { cbs } {
- global repeatStatus text
-
- fortuneCB $text $cbs
-
- set repeatStatus [ WsAddTimeOut \
- -callback { TOfortuneCB } \
- -interval 2000 \
- ]
- # puts $repeatStatus
- }
-
- # setup initial call to make fortune repeat
- proc RepeatCB { cbs } {
- global repeatStatus
-
- if { $repeatStatus != "" } {
- WsRemoveTimeOut $repeatStatus
- set repeatStatus ""
- } \
- else \
- {
- set repeatStatus [ WsAddTimeOut \
- -callback { TOfortuneCB } \
- -interval 100 \
- ]
- }
-
- }
-
- # ---------------- Widget Hier Setup procs ----------------
-
- # -- MenuBar --
- proc genericCB {cbs } {}
-
- proc mkMenuBar { parent } {
-
- # pulldown : pd name mnemonic accel
- # button : bt name mnemonic accel accelString Callback
- # separator: sp
-
- set menuList {
- {pd File P}
- {bt Reset R "" "" FileMenuResetCB }
- {sp}
- {bt Exit E "" "" quitCB }
-
- {pd View V}
- {bt LargeFont A "" "" nyiCB }
- {bt SmallFont F "" "" nyiCB }
- }
-
-
- set menubar [VtMenuBar $parent.menubar -helpMenuItemList {INDEX ON_VERSION}]
- VxMenu $parent $menubar $menuList genericCB
-
- return $menubar
- }
-
-
- # -- Config items frame and buttons --
- proc mkConfigBtns { parent { Top "FORM" } { Left "FORM"} {Right "FORM"} } {
-
- set frame [ VtFrame $parent.frame \
- -title "Config" \
- -shadowType ETCHED_IN \
- -topSide $Top \
- -leftSide $Left \
- -rightSide $Right \
- ]
-
- set fform [ VtForm $frame.form ]
-
- set btn2 [ VtPushButton $fform.b2 \
- -label Files \
- -callback { set arg "-f" ; fortuneCB $text } \
- ]
-
- set btn3 [ VtPushButton $fform.b3 \
- -label Short \
- -callback { set arg "-s" ; fortuneCB $text }
- ]
-
- set btn4 [ VtPushButton $fform.b4 \
- -label Repeat... \
- -callback { RepeatCB } \
- ]
- return $frame
- }
-
-
- #---- Main program Widget Logic ----
-
- # mainline
-
- # Open Server connection
- set app [VtOpen Fortune ]
-
- VtSetAppValues $app -versionString "Fortune 1.0\n Hops 08.19.94"
-
- # Make popup Form
- set form [ VtFormDialog $app.form \
- -title "Fortune" \
- -wmCloseCallback quitCB \
- ]
-
-
- set mb [ mkMenuBar $form]
-
- #set top FORM
- set top $mb
-
- # Field for Display of fortune string
- set text [ VtText $form.text \
- -readOnly \
- -columns 60 \
- -horizontalScrollBar TRUE \
- -verticalScrollBar TRUE \
- -rows 10 \
- -topSide $top \
- -leftSide FORM \
- ]
-
- # -wordWrap
-
-
- # Combobox for selection of fortune file
- set lbl [ VtLabel $form.lbl -label "Fortune File" \
- -topSide $text\
- ]
-
- # Now Buttons ( RHS )
- set cb [ VtComboBox $form.combo \
- -value $FortFile \
- -itemList $Fortunes_File_List \
- -valueChangedCallback CBFileItemCB \
- -topSide $lbl \
- -bottomSide FORM \
- ]
-
- # Btn for a single fortune
- set btn1 [ VtPushButton $form.btn1 \
- -label "Fortune" \
- -callback { fortuneCB $text } \
- -leftSide $text \
- -topSide $top \
- -rightSide FORM \
- ]
-
- # Config Box
- set frame [ mkConfigBtns $form $btn1 $text ]
-
-
- # Quit Btn
- set btnE [ VtPushButton $form.bE \
- -label Quit \
- -callback { quitCB } \
- -topSide $frame \
- -leftSide $text \
- -rightSide FORM \
- ]
-
-
-
- # Start everything going
- VtShow $form
- VtMainLoop
-